<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : desert.xsl
    Created on : 28. duben 2011, 18:30
    Author     : newohybat newohybat@gmail.com
    Description:
        Stylesheet to transform source data(xhtml) to internal representation (xml - internalConcerts)
-->

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://code.google.com/p/kalkon/internalConcerts">

    <xsl:output method="xml"
                encoding="UTF-8"
                indent="yes"
                media-type="text/xml"/>


<!-- Create concerts  -->
    <xsl:template match="/html">
        <concerts>
            <xsl:attribute name="id">desert</xsl:attribute>
            <xsl:apply-templates select="//tbody/tr"/>
        </concerts>
    </xsl:template>
<!--  Build concert  -->
    <xsl:template match="//tbody/tr">
        <concert>
            <xsl:apply-templates select="td[@headers='el_title']/a"/>
            <description><xsl:value-of select="normalize-space(td[@headers='el_category']/a)"/></description>
            <location>Klub Desert, Rooseveltova 11, Brno</location>
            <xsl:apply-templates select="td[@headers='el_date']"/>
        </concert>
    </xsl:template>
<!-- Build day_start and time_start-->
    <xsl:template match="//td[@headers='el_date']">
        <xsl:variable name="datetoparse"><xsl:value-of select="normalize-space(strong)"/></xsl:variable> <!-- get date string-->
        <xsl:variable name="year"><xsl:value-of select="substring($datetoparse,string-length($datetoparse)-3,4)"/></xsl:variable> <!-- Parse YEAR-->
        <xsl:variable name="month"><xsl:value-of select="substring-before(substring-after($datetoparse,'.'),'.')"/></xsl:variable> <!-- Parse MONTH-->
        <xsl:variable name="day"><xsl:value-of select="substring-before($datetoparse,'.')"/></xsl:variable> <!-- Parse DAY-->
        <xsl:variable name="timetoparse"><xsl:value-of select="normalize-space(child::text()[last()])"/></xsl:variable>
        <xsl:variable name="hours"><xsl:value-of select="substring-before($timetoparse,'.')"/></xsl:variable>
        <xsl:variable name="minutes"><xsl:value-of select="substring-before(substring-after($timetoparse,'.'),' ')"/></xsl:variable>
        <xsl:variable name="seconds"><xsl:text>00</xsl:text></xsl:variable>
        <day_start><xsl:value-of select="concat($year,$month,$day)"/></day_start>
        <time_start><xsl:value-of select="concat($hours,$minutes,$seconds)"/></time_start>
    </xsl:template>
<!--  Build title  -->
    <xsl:template match="//td[@headers='el_title']/a">
        <title><xsl:value-of select="normalize-space(.)"/></title>
    </xsl:template>
</xsl:stylesheet>
